in vec4 color; //The color passed in from the vertex shader (interpolated)
#ifdef MY_BUMPMAP
in vec3 B;
in vec3 T;
#endif
in vec3 N;
in vec2 texcoord0;
//out vec4 outColor; //Define the output of our fragment shader

#ifdef MY_DIFFUSE
	uniform sampler2D MY_DIFFUSE;
#endif

#ifdef MY_BUMPMAP
	uniform sampler2D MY_BUMPMAP;
#endif

void main(void)
{
	vec4 diffuse = color;
	
	#ifdef MY_DIFFUSE
		diffuse = texture(MY_DIFFUSE, texcoord0);
	#endif
	
	vec3 normal = N;
	#ifdef MY_BUMPMAP
		vec4 bumpcolor = texture(MY_BUMPMAP, texcoord0);
		
		normal.xy = bumpcolor.ag * 2.0 - 1.0;
		normal.z = sqrt(1.0 - normal.x * normal.x - normal.y * normal.y);
		
		float bumpscale = 1.0;
		normal.z /= bumpscale;
		normal = T * normal.x + B * normal.y + N * normal.z;
	#endif
	
	gl_FragData[0] = diffuse;
	gl_FragData[1] = vec4(normalize(normal)*0.5f+0.5f,1.0f);
	gl_FragData[2] = vec4(0.5f);
	gl_FragData[3] = vec4(0.0f);

	//outColor = color * vec4(texcoord0,0.0,1.0);
}